package ch.bfh.fbi.mobicomp.zap05;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class Zap05MessageBroadcastReceiver extends BroadcastReceiver {
	private static final String TAG = "ZAP05";
	public static final String REMOTE_ZAPPER_MESSAGE_RECEIVED = "ch.bfh.fbi.mobicomp.zap05.Zap05MessageBroadcastReceiver.MESSAGE_RECEIVED_ACTION";
	public static final String MESSAGE = "message";

	public static Intent getRemoteZapperMessageIntent(final String message) {
		final Intent intent = new Intent(
				Zap05MessageBroadcastReceiver.REMOTE_ZAPPER_MESSAGE_RECEIVED);
		intent.putExtra(Zap05MessageBroadcastReceiver.MESSAGE, message);
		return intent;
	}

	@Override
	public void onReceive(final Context context, final Intent intent) {
		Log.d(Zap05MessageBroadcastReceiver.TAG, "Intent received: " + intent);
		if (intent != null) {
			final String message = intent
					.getStringExtra(Zap05MessageBroadcastReceiver.MESSAGE);
			final Intent zapperIntent = Zap05Service.getZapperIntent(message);
			Log.d(Zap05MessageBroadcastReceiver.TAG,
					"Sending intent to service: " + zapperIntent);
			context.startService(zapperIntent);
			Log.d(Zap05MessageBroadcastReceiver.TAG, "Intent sent to service");
		}
	}
}